package cn.wolfcode.lww.controller;

import cn.wolfcode.lww.domain.Hotsell;
import cn.wolfcode.lww.domain.Strategy;
import cn.wolfcode.lww.domain.Travelnotes;
import cn.wolfcode.lww.service.impl.HotSellServiceImpl;
import cn.wolfcode.lww.service.impl.StrategyServiceImpl;
import cn.wolfcode.lww.service.impl.TravelnotesServiceImpl;
import cn.wolfcode.lww.util.QueryObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class SearchController {
    @Autowired
    StrategyServiceImpl strategyService;
    @Autowired
    HotSellServiceImpl hotSellService;
    @Autowired
    TravelnotesServiceImpl travelnotesService;
@RequestMapping("/search")
    public String search(String searchType, String searchText, QueryObject queryObject, Model model){
    if (searchType.equals("攻略")){

        String searchText1="%"+searchText+"%";
        PageInfo<Strategy> strategyPageInfo = strategyService.searchAllByTitle(queryObject,searchText1);
        model.addAttribute("list",strategyPageInfo);
        List<Hotsell> hotsells = hotSellService.selectAll();
        model.addAttribute("hotSellList",hotsells);
        return "strategy/strategy";

}else if(searchType.equals("游记")){
        String searchText1="%"+searchText+"%";
        PageInfo<Travelnotes> travelnotesPageInfo=travelnotesService.searchAllByTitle(queryObject,searchText1);
        model.addAttribute("list",travelnotesPageInfo);
        List<Hotsell> hotsells = hotSellService.selectAll();
        model.addAttribute("hotSellList",hotsells);
        return "travel/travel_journal";
    }
    return "index/index";
}}
